import RPi.GPIO as GPIO
import time

# use physical pin numbers
GPIO.setmode(GPIO.BOARD)

# switch off GPIO warnings
GPIO.setwarnings(False)

output_pin = [3,5,7,8,10,11,12]
input_pin = 26
pin_mapping = {1:[8],2:[3,12],3:[3,8,12],4:[3,7,10,12],5:[3,7,8,10,12],6:[3,5,7,10,11,12]}

def init():
  # setup output pins, switch pins off
  for i in output_pin:
    GPIO.setup(i,GPIO.OUT,initial=0)  
  # setup input pin; enable internal pull down resistor
  GPIO.setup(input_pin,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)

def description():
  print ('dice pidget methods:')
  print ('  init():          initializes input and output pins')
  print ('  set_dice([0,6]): sets LEDs to given number')
  print ('  get_switch():    returns state of switch')
  print ('  test():          flashes all 7 LEDs for 1 second')

def set_dice(number):
  for i in output_pin:
    GPIO.output(i,0)
  if number in pin_mapping:
    for i in pin_mapping[number]:
      GPIO.output(i,1)

def get_switch():
  return GPIO.input(26)

def test():
  for i in output_pin:
    GPIO.output(i,1)
  time.sleep(1)
  for i in output_pin:
    GPIO.output(i,0)


